﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar;
using CommDll;

namespace InstitutionAssitant
{
    /// <summary>
    /// ClassName:frmTemp
    /// Version:1.0
    /// Date:2016-06-23
    /// Author:seanouyang
    /// </summary>
    /// <remarks>
    /// 本类是一WinForm 窗体,本窗体主要为实现...
    /// </remarks>
    public partial class frmInvoiceSet : DevComponents.DotNetBar.OfficeForm
    {
        #region 01.自定义属性
        public Dictionary<string, string> m_dictInfo = new Dictionary<string, string>();
        public frmInvoiceSet()
        {
            InitializeComponent();
        }
        #endregion

        #region 02.自定义方法
        /// <summary>
        /// 初始化
        /// </summary>
        private void _init()
        {
            //txtInvoiceCode.Text = m_dictInfo.ContainsKey("InvoiceCode") ? m_dictInfo["InvoiceCode"] : "";
            txtInvoiceNo.Text = m_dictInfo.ContainsKey("InvoiceNo") ? m_dictInfo["InvoiceNo"] : "";
            dtpInvoiceDate.Value = FunctionComm._strToDatetime(m_dictInfo.ContainsKey("InvoiceDate") ? m_dictInfo["InvoiceDate"] : "");
        }

        /// <summary>
        /// 保存信息
        /// </summary>
        private void _saveInfo()
        {
            //m_dictInfo["InvoiceCode"] = txtInvoiceCode.Text.Trim();
            m_dictInfo["InvoiceNo"] = txtInvoiceNo.Text.Trim();
            m_dictInfo["InvoiceDate"] = dtpInvoiceDate.Value.ToString("yyyy-MM-dd");
            string strSql = "Update T_DeliveryDetail set InvoiceCode = InvoiceCode,InvoiceNo = '{2}',InvoiceDate = '{3}',ReservedField4 = '发票号重置:' + Convert(varchar(20),getDate(),120) where ID = {0}";
            strSql = string.Format(strSql, m_dictInfo["ID"].Replace("'","''")
                ,""//m_dictInfo["InvoiceCode"].Replace("'","''")
                , m_dictInfo["InvoiceNo"].Replace("'", "''")
                , m_dictInfo["InvoiceDate"]
                );
            DbHelper.DBAccess[0]._execSql(strSql);
        }
        #endregion

        #region 03.系统事件方法
        private void btnSave_Click(object sender, EventArgs e)
        {
            _saveInfo();
            this.DialogResult = DialogResult.OK;
        }

        private void btnReturn_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        #endregion        

        private void frmInvoiceSet_Load(object sender, EventArgs e)
        {
            _init();
        }
    }
}